import { Menu } from '@tauri-apps/api/menu';
import { TrayIcon} from '@tauri-apps/api/tray';
import { defaultWindowIcon } from '@tauri-apps/api/app';
import { Image } from '@tauri-apps/api/image';

function onTrayMenuClick(itemId:any) {
  // itemId === 'quit'
  console.log(itemId)
}


const menu = await Menu.new({
  items: [
    {
      id: 'quit',
      text: 'Quit',
      action: onTrayMenuClick,
    },
  ],
});


const tray = await TrayIcon.new({
  menu,
  menuOnLeftClick: true,
  icon: await defaultWindowIcon(),//Image.fromPath(iconPath),
  tooltip: 'awesome tray tooltip',
  action: (event:any) => {
    switch (event.type) {
      case 'Click':
        console.log(
          `mouse ${event.button} button pressed, state: ${event.buttonState}`
        );
        break;
      case 'DoubleClick':
        console.log(`mouse ${event.button} button pressed`);
        break;
      case 'Enter':
        console.log(
          `mouse hovered tray at ${event.rect.position.x}, ${event.rect.position.y}`
        );
        break;
      case 'Move':
        console.log(
          `mouse moved on tray at ${event.rect.position.x}, ${event.rect.position.y}`
        );
        break;
      case 'Leave':
        console.log(
          `mouse left tray at ${event.rect.position.x}, ${event.rect.position.y}`
        );
        break;
    }
  },
});
tray.setTooltip('new tooltip');
